<?php
/**
 * @author Jurunlong <hipop@126.com>
 * 
 */
class Zend_View_Helper_Jqflexgrid{
	/**
	 * 
	 * 将键值对数据转换成flexgrid可识别的数据，并供json输出
	 * @param array $arr
	 */
	public function jqflexgrid($arr=null,$page=1,$total=0,$key=NULL){
		if(isset($arr["data"]) &&
		isset($arr["total"])&&
		isset($arr["page"])) 
		return $this->jqflexgrid($arr["data"],$arr["page"],$arr["total"],$page);
		
		if(!$arr){
			$arr = array();
		}
		//$page = $page?$page:1;
		$total =$total?$total:count($arr);
		$data = array(
			"page"  => $page,
			"total" => $total,
			"rows"  => array()
		);
		foreach ($arr as $k => $v){
			$data['rows'][]=array(
				'no'=>$k+1,
				'id'=>$key?($v[$key]?$v[$key]:0):$k+1,
				'cell'=>$v
			);
		}
		return $data;
	}
}